package com.lineage.data.item_etcitem;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.ExpTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SetLevel_Reel extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(SetLevel_Reel.class);
  
  private int _levelupto = 1;
  
  public static ItemExecutor get() {
    return new SetLevel_Reel();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    try {
      if (item == null)
        return; 
      if (pc == null)
        return; 
      pc.getInventory().removeItem(item, 1L);
      if (this._levelupto <= pc.getLevel()) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("你目前等级已经够了"));
        return;
      } 
      pc.setExp_Direct(ExpTable.getExpByLevel(this._levelupto));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._levelupto = Integer.parseInt(set[1]);
      if (this._levelupto <= 0) {
        _log.error("UserHpr 设置错误:最小恢复质小于等于0! 使用预设1");
        this._levelupto = 50;
      } 
    } catch (Exception exception) {}
  }
}
